Skip to content

fix: search_code returns not indexed even when VectorDB has data (#226)#283

Merged
zc277584121 merged 2 commits intozilliztech:masterfrom
zc277584121:fix/search-not-indexed-226
Mar 12, 2026
Merged

fix: search_code returns not indexed even when VectorDB has data (#226)#283
zc277584121 merged 2 commits intozilliztech:masterfrom
zc277584121:fix/search-not-indexed-226

Conversation

@zc277584121
Copy link
Collaborator

Summary

  • Fix snapshot read-merge-write re-add bug: Added recentlyRemoved Set to SnapshotManager to prevent mergeExternalEntry() from re-adding codebases that were just removed via removeCodebaseCompletely() during the save's read-merge-write cycle.
  • Fix search_code false negatives (claude-context MCP search_code fails despite successful indexing #226): Four changes to handlers.ts:
    1. Bidirectional cloud sync — recover cloud codebases missing from local snapshot
    2. Search VectorDB fallback — check VectorDB directly before returning "not indexed" error
    3. Fix empty filter in sync query (''undefined)
    4. Index mismatch auto-repair — auto-fix snapshot/VectorDB inconsistency instead of just warning

Root Cause

The snapshot file is the sole arbiter of whether a codebase is indexed, but it can lose entries due to:

  • Multi-process race conditions (another Claude session overwrites the snapshot)
  • File corruption or manual edits
  • The read-merge-write pattern re-adding removed entries

When the snapshot loses track, search_code returns "not indexed" even though VectorDB has perfectly valid index data.

Fix Approach

Make VectorDB the source of truth by adding fallback checks at every code path:

  • sync: bidirectional recovery from cloud
  • search: VectorDB fallback before error
  • index: mismatch detection and auto-repair
  • snapshot: prevent read-merge-write from undoing removals

Test Plan

  • E2E Test 1: Normal index + search
  • E2E Test 2: Search after snapshot cleared (same MCP session) — VectorDB fallback works
  • E2E Test 3: Search after MCP cold restart with empty snapshot — cloud sync recovery works
  • E2E Test 4: Snapshot/VectorDB mismatch auto-fix during index — recentlyRemoved prevents re-add

Closes #226

…pshot

Add recentlyRemoved Set to SnapshotManager to track codebases that were
explicitly removed via removeCodebaseCompletely(). The mergeExternalEntry()
method now checks this set and skips re-adding entries from disk that were
intentionally removed. The set is cleared after each successful save.

This fixes a bug where the read-merge-write pattern in saveCodebaseSnapshot()
would read old disk data and merge back entries that had just been removed
from memory, causing removed codebases to reappear in the snapshot.

Signed-off-by: Cheney Zhang <chen.zhang@zilliz.com>
…liztech#226)

Four changes to fix search_code false negatives caused by snapshot losing
track of indexed codebases:

1. Bidirectional cloud sync: recover cloud codebases missing from local
   snapshot during syncIndexedCodebasesFromCloud(), instead of skipping them.

2. Search VectorDB fallback: when snapshot says not indexed, check VectorDB
   directly before returning error. If VectorDB has the index, recover the
   snapshot entry and continue with search.

3. Fix empty filter in sync query: pass undefined instead of empty string
   to vectorDb.query() to avoid failures on local Milvus.

4. Index mismatch auto-repair: when snapshot and VectorDB disagree during
   index_codebase, auto-fix by either recovering or clearing the snapshot
   entry, instead of just logging a warning.

Signed-off-by: Cheney Zhang <chen.zhang@zilliz.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

claude-context MCP search_code fails despite successful indexing

1 participant